#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <vector>
#include <set>
#include <queue>

using namespace std;
using LL = long long;
using PII = pair<int, int>;

const int N = 1010;
LL n, c;
LL q[N], sum[N];
LL total = 0;

void dfs(int index, LL s){

    
    total = max(total, s);
  

    if(index == 1) return;

    if(sum[index - 1] + s <= c){
        total = max(total, sum[index - 1] + s);


        return;
    }

    for(int i = index - 1; i >= 1; i --){
        if(sum[i] + s <= c){
            total = max(total, sum[i] + s);
            break;
        }
    }
    
    

    if(s + q[index - 1] <= c){
        dfs(index - 1, s + q[index - 1]);
    }
    dfs(index - 1, s);


}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> c;
    for(int i = 1; i <= n; i ++) {
        cin >> q[i];
        sum[i] = sum[i - 1] + q[i];
    }
 
    dfs(n + 1, 0);
    cout << total << '\n';

    

    return 0;
}